package com.esd.db.service.impl;

import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.alipay.api.AlipayApiException;
import com.esd.db.dao.AlipayInfoMapper;
import com.esd.db.dao.VtdParameterMapper;
import com.esd.db.dao.salaryMapper;
import com.esd.db.dao.workerMapper;
import com.esd.db.model.AlipayInfo;
import com.esd.db.model.VtdParameter;
import com.esd.db.model.salary;
import com.esd.db.model.worker;
import com.esd.db.service.SalaryService;
import com.esd.db.tool.AlipayUtils;
@Service("SalaryService")
public class SalaryServiceImpl implements SalaryService {
	@Autowired
	salaryMapper salaryMapper;
	@Autowired
	workerMapper workerMapper;
	@Autowired
	VtdParameterMapper paramMapper;
	@Autowired
	AlipayInfoMapper payInfoMapper;
	
	@Override
	public int deleteByPrimaryKey(Integer id) {
		
		return salaryMapper.deleteByPrimaryKey(id);
	}

	@Override
	public int insert(salary record) {
		
		return salaryMapper.insert(record);
	}

	@Override
	public int insertSelective(salary record) {
		
		return salaryMapper.insertSelective(record);
	}

	@Override
	public salary getByPrimaryKey(Integer id) {
		
		return salaryMapper.selectByPrimaryKey(id);
	}

	@Override
	public int updateByPrimaryKeySelective(salary record) {
		
		return salaryMapper.updateByPrimaryKeySelective(record);
	}

	@Override
	public int updateByPrimaryKey(salary record) {
		
		return salaryMapper.updateByPrimaryKey(record);
	}

	@Override
	public AlipayInfo insertTimer(int workerId,String uploadUUID) {
		//TODO 初审工资处理
		//查询过审任务中的一层和三层任务的信息
		Map<String,Object> map = new HashMap<>();
		map.put("workerId", workerId);
		map.put("uploadUUID", uploadUUID);
		AlipayInfo payInfo = null;
		List<Map<String,Object>> salaryInfos = salaryMapper.selectInfoToInsertSalaryForInspByWorker(map);
		if(!salaryInfos.isEmpty()){
			payInfo = this.alipaySendAndSalaryInsert(workerId, salaryInfos, map);
		}
		return payInfo;
	}

	@Override
	public List<Map<String, Object>> getSalary(int dateType, int page, int row, String beginDate, String endDate, String realName,int salaryLine,int payOffType,String workGroupCode) {
		Map<String,Object> map = new HashMap<>();
		map.put("dateType", dateType);
		map.put("payOffType",payOffType);
		if (page == 0) {
			map.put("begin", null);
			map.put("end", null);
		} else {
			map.put("begin", ((page - 1) * row));
			map.put("end", row);
		}
		map.put("beginDate", beginDate);
		map.put("endDate", endDate);
		if(salaryLine >= 0){
			map.put("salaryLine", salaryLine*18);
		}else{
			map.put("salaryLine", null);
		}	
		if(realName.trim().length()>0){
			map.put("realName", realName);
		}else{
			map.put("realName", null);
		}	
		map.put("workGroupCode", workGroupCode);
		return salaryMapper.selectSalary(map);
	}

	@Override
	public int getSalary100Count(int dateType, String beginDate, String endDate, String realName,int salaryLine,int payOffType,String workGroupCode) {
		Map<String,Object> map = new HashMap<>();
		map.put("dateType", dateType);
		map.put("payOffType",payOffType);
		map.put("beginDate", beginDate);
		map.put("endDate", endDate);
		if(salaryLine >= 0){
			map.put("salaryLine", salaryLine*18);
		}else{
			map.put("salaryLine", null);
		}		
		if(realName.trim().length()>0){
			map.put("realName", realName);
		}else{
			map.put("realName", null);
		}
		map.put("workGroupCode", workGroupCode);
		return salaryMapper.selectSalary100Count(map);
	}

	@Override
	public Double getSUMSalary(int dateType, String beginDate, String endDate, String realName,int salaryLine,int payOffType) {
		Map<String,Object> map = new HashMap<>();
		map.put("dateType", dateType);
		map.put("payOffType",payOffType);
		map.put("beginDate", beginDate);
		map.put("endDate", endDate);
		if(salaryLine >= 0){
			map.put("salaryLine", salaryLine*18);
		}else{
			map.put("salaryLine", null);
		}	
		if(realName.trim().length()>0){
			map.put("realName", realName);
		}else{
			map.put("realName", null);
		}
		return salaryMapper.selectSUMSalary(map);
	}

	@Override
	public List<Map<String, Object>> getWorkerSalaryByWorkerId(int workerId) {
		Map<String,Object> map = new HashMap<>();
		map.put("workerId", workerId);
		return salaryMapper.selectWorkerSalaryByWorkerId(map);
	}

	//榜单
	public List<Map<String, Object>> getMoneyList(String beginDate, String endDate, String month) {
		Map<String,Object> map = new HashMap<>();
		if(month.trim().length()>0){
			map.put("month",month);
		}
		if(endDate.trim().length()>0){
			map.put("beginDate", beginDate);
			map.put("endDate", endDate);
		}
		return salaryMapper.selectMoneyList2(map);
	}

	@Override
	public Double getSumMarkTime2(int workerId, String nowMonth) {
		Map<String,Object> map = new HashMap<>();
		map.put("workerId", workerId);
		map.put("nowMonth", nowMonth);
		return salaryMapper.selectSumMarkTime2(map);
	}

	//插入结算数据
	public int insertPayOffInfor(int dateType, String beginDate, String endDate, String realName, int salaryLine, String payOffTime) {
		Map<String,Object> map = new HashMap<>();
		map.put("dateType", dateType);
		map.put("beginDate", beginDate);
		map.put("endDate", endDate);
		if(realName.trim().length()>0){
			map.put("realName", realName);
		}else{
			map.put("realName", null);
		}	
		map.put("salaryLine", salaryLine);
		map.put("payOffTime", payOffTime);
		return salaryMapper.insertPayOffInfor(map);
	}

	@Override
	public int insertPayOffInfor1(int dateType, String beginDate, String endDate, String[] workerId, String timer) {
		Map<String,Object> map = new HashMap<>();
			map.put("dateType", dateType);
			map.put("beginDate", beginDate);
			map.put("endDate", endDate);
			map.put("workerId", workerId);
			map.put("timer", timer);
		return salaryMapper.insertPayOffInfor1(map);
	}

	@Override
	public Double getMoneyTotle(int today) {
		Map<String,Object> map = new HashMap<>();
		map.put("today", today);		
		return salaryMapper.selectMoneyTotle(map);
	}
	
	@Override
	public AlipayInfo insertSalary(int workerId,int packId) {
		//TODO 包审工资处理
		Map<String,Object> map = new HashMap<String,Object>();
		map.put("packId", packId);
		map.put("workerId", workerId);
		map.put("salaryCountFlag", 0);   //计算工资标志  添加未计算过工资的数据
		AlipayInfo payInfo = null;
		List<Map<String,Object>> salaryInfos = salaryMapper.selectInfoToInsertSalaryForInspByPackage(map);
		if(!salaryInfos.isEmpty()){
			payInfo = this.alipaySendAndSalaryInsert(workerId, salaryInfos, map);
		}
		return payInfo;	
	}
	
	@Override
	public AlipayInfo insertSalaryForQuickInspection(int workerId,int packId) {
		//TODO  快速审核工资处理
		Map<String,Object> map = new HashMap<String,Object>();
		map.put("packId", packId);
		map.put("workerId", workerId);
		map.put("salaryCountFlag", 0);   //计算工资标志  添加未计算过工资的数据
		//循环workerId 查询需要退回的数据然后对salary进行更新
		AlipayInfo payInfo = null;
		List<Map<String,Object>> salaryInfos = salaryMapper.selectInfoToInsertSalaryForQuickInspection(map);
		if(!salaryInfos.isEmpty()){
			payInfo = this.alipaySendAndSalaryInsert(workerId, salaryInfos, map);
		}
		return payInfo;	
	}

	@Override
	public List<Map<String, Object>> getWorkGroupCodeAndSumMarkTimeList(int dateType, int page, int row, String beginDate, String endDate, String workGroupNameCondition) {
		Map<String,Object> map = new HashMap<>();
		map.put("dateType", dateType);
		map.put("beginDate", beginDate);
		map.put("endDate", endDate);
		if (page == 0) {
			map.put("begin", null);
			map.put("end", null);
		} else {
			map.put("begin", ((page - 1) * row));
			map.put("end", row);
		}
		if(workGroupNameCondition.trim().length()>0){
			map.put("workGroupName", workGroupNameCondition);
		}else{
			map.put("workGroupName", null);
		}
		return salaryMapper.getWorkGroupCodeAndSumMarkTimeList(map);
	}

	@Override
	public int getWorkGroupListCount(int dateType, String beginDate, String endDate, String workGroupNameCondition) {
		Map<String,Object> map = new HashMap<>();
		map.put("dateType", dateType);
		map.put("beginDate", beginDate);
		map.put("endDate", endDate);
		
		if(workGroupNameCondition.trim().length()>0){
			map.put("workGroupName", workGroupNameCondition);
		}else{
			map.put("workGroupName", null);
		}
		return salaryMapper.selectWorkGroupListCount(map);
	}

	@Override
	public List<AlipayInfo> insertSalaryForInspByDay(String insDate, String searchTime, String workGroupCode, List<Integer> recordIds) {
		//TODO 巡审工资处理
		Map<String,Object> map = new HashMap<String,Object>();
		//查询巡审审核的所有符合条件的的工作者id
		map.put("workGroupCode", workGroupCode);
		map.put("searchTime", searchTime);
		map.put("insDate", insDate);
		map.put("recordIds", recordIds);
		List<Integer> workerIds = salaryMapper.selectWorkerIdForInspByDay(map);
		//向表中插入数据
		List<AlipayInfo> payList = new ArrayList<AlipayInfo>();
		if(!workerIds.isEmpty()){
			for (int i = 0; i < workerIds.size(); i++) {
				map.put("workerId", workerIds.get(i));
				map.put("salaryCountFlag", 0);   //计算工资标志  添加未计算过工资的数据
				List<Map<String,Object>> salaryInfos = salaryMapper.selectInfoToInsertSalaryForInspByDay(map);
				if(!salaryInfos.isEmpty()){
					AlipayInfo payInfo = this.alipaySendAndSalaryInsert(workerIds.get(i), salaryInfos, map);
					if(payInfo!=null){
						payList.add(payInfo);						
					}
				}
			}
		}
		return payList;
	}

	@Override
	public int subtractFromSalaryForInspByDay(int[] workerIds, String searchTime, String insDate) {
//		Map<String,Object> map = new HashMap<String,Object>();
//		map.put("insDate", insDate);
//		//循环workerId 查询需要退回的数据然后对salary进行更新
//		int count = 0;
//		for (int i = 0; i < workerIds.length; i++) {
//			map.put("workerId", workerIds[i]);
//			//计算退回的时间
//			double sumMarkTime = salaryMapper.getSumMarkTimeForInspByDay(map);
//			map.put("sumMarkTime", sumMarkTime);
//			// 将退回时间存入salary表中 存为负数
//			count = salaryMapper.insertSendBackTime(map);
//		}
		
		Map<String,Object> map = new HashMap<String,Object>();
		map.put("insDate", insDate);
		map.put("searchTime", searchTime);
		//循环workerId 查询需要退回的数据然后对salary进行更新
		int count = 0;
		for (int i = 0; i < workerIds.length; i++) {
			map.put("workerId", workerIds[i]);
			map.put("salaryCountFlag", 1);   //计算工资标志  添加已经计算过工资的数据
			List<Map<String,Object>> salaryInfos = salaryMapper.selectInfoToInsertSalaryForInspByDay(map);
			if(!salaryInfos.isEmpty()){
				worker worker = workerMapper.selectByPrimaryKey(workerIds[i]);
				List<Map<String,Object>> salaryInfoForInsert = this.getInsertInfoListByWorkerIdAndSalaryInfo(worker, salaryInfos);
				map.put("salaryInfoForInsert", salaryInfoForInsert);
				salaryMapper.insertSendBackTime(map);
			}
		}
		return count;
	}

	@Override
	public int subtractFromSalaryForInspByPackage(int[] workerIds, int packId, int sendBackType, int[] unqualifiedTaskIds) {
//		Map<String,Object> map = new HashMap<String,Object>();
//		map.put("packId", packId);
//		if(sendBackType==1){
//			map.put("taskIds", unqualifiedTaskIds);
//			map.put("sendBackType", sendBackType);			
//		}else{
//			map.put("sendBackType", null);			
//		}
//		//循环workerId 查询需要退回的数据然后对salary进行更新
//		int count = 0;
//		for (int i = 0; i < workerIds.length; i++) {
//			map.put("workerId", workerIds[i]);
//			//计算退回的时间
//			double sumMarkTime = salaryMapper.getSumMarkTimeForInspByPackage(map);
//			map.put("sumMarkTime", sumMarkTime);
//			// 将退回时间存入salary表中 存为负数
//			count = salaryMapper.insertSendBackTime(map);
//		}
//		return count;
		Map<String,Object> map = new HashMap<String,Object>();
		map.put("packId", packId);
		if(sendBackType==1){
			map.put("taskIds", unqualifiedTaskIds);
			map.put("sendBackType", sendBackType);			
		}else{
			map.put("sendBackType", null);			
		}
		//循环workerId 查询需要退回的数据然后对salary进行更新
		int count = 0;
		for (int i = 0; i < workerIds.length; i++) {
			int salaryCountTiming = 0;
			List<VtdParameter> outsourcerCodeList = paramMapper.selectParamByType("outsourcerCodes");  //外包商组代码  数据库中只存一条信息  	
			VtdParameter param = outsourcerCodeList.get(0);
	    	String[] outsourcerCodes = param.getParamValue().split(",");
	    	worker w = workerMapper.selectByPrimaryKey(workerIds[i]);
	    	boolean flag = true;
		    for (int j = 0; j < outsourcerCodes.length; j++) {
				if (w.getWorkGroupCode().equals(outsourcerCodes[j])) {
					flag = false;  //审核的是外包工作者
				}
			}
			List<VtdParameter> paramList = null;
			if(flag){
				paramList = paramMapper.selectParamByType("salaryCountTiming");//查询结算设置用的参数 只有一条数据   自营
			}else{
				paramList = paramMapper.selectParamByType("outsourcerSalaryCountTiming");//查询外包结算设置用的参数 只有一条数据  外包
			}
			if(!paramList.isEmpty()){
				VtdParameter vp = paramList.get(0);
				salaryCountTiming = Integer.parseInt(vp.getParamValue());
			}
			if(salaryCountTiming < 3){
				map.put("workerId", workerIds[i]);
				map.put("salaryCountFlag", 1);   //计算工资标志  添加已经计算过工资的数据
				List<Map<String,Object>> salaryInfos = salaryMapper.selectInfoToInsertSalaryForInspByPackage(map);
				if(!salaryInfos.isEmpty()){	
					worker worker = workerMapper.selectByPrimaryKey(workerIds[i]);
					List<Map<String,Object>> salaryInfoForInsert = this.getInsertInfoListByWorkerIdAndSalaryInfo(worker, salaryInfos);
					map.put("salaryInfoForInsert", salaryInfoForInsert);
					salaryMapper.insertSendBackTime(map);
				}
			}
		}
		return count;	
	}
	
	@Override
	public int subtractFromSalaryForQuickInspection(int[] workerIds, int packId) {
//		Map<String,Object> map = new HashMap<String,Object>();
//		map.put("packId", packId);
//		//循环workerId 查询需要退回的数据然后对salary进行更新
//		int count = 0;
//		for (int i = 0; i < workerIds.length; i++) {
//			map.put("workerId", workerIds[i]);
//			//计算退回的时间
//			double sumMarkTime = salaryMapper.getSumMarkTimeForQuickInspection(map);
//			map.put("sumMarkTime", sumMarkTime);
//			// 将退回时间存入salary表中 存为负数
//			count = salaryMapper.insertSendBackTime(map);
//		}
//		return count;
		
		Map<String,Object> map = new HashMap<String,Object>();
		map.put("packId", packId);
		//循环workerId 查询需要退回的数据然后对salary进行更新
		int count = 0;
		for (int i = 0; i < workerIds.length; i++) {
			int salaryCountTiming = 0;
			List<VtdParameter> outsourcerCodeList = paramMapper.selectParamByType("outsourcerCodes");  //外包商组代码  数据库中只存一条信息  	
			VtdParameter param = outsourcerCodeList.get(0);
	    	String[] outsourcerCodes = param.getParamValue().split(",");
	    	worker w = workerMapper.selectByPrimaryKey(workerIds[i]);
	    	boolean flag = true;
		    for (int j = 0; j < outsourcerCodes.length; j++) {
				if (w.getWorkGroupCode().equals(outsourcerCodes[j])) {
					flag = false;  //审核的是外包工作者
				}
			}
			List<VtdParameter> paramList = null;
			if(flag){
				paramList = paramMapper.selectParamByType("salaryCountTiming");//查询结算设置用的参数 只有一条数据   自营
			}else{
				paramList = paramMapper.selectParamByType("outsourcerSalaryCountTiming");//查询外包结算设置用的参数 只有一条数据  外包
			}
			if(!paramList.isEmpty()){
				VtdParameter vp = paramList.get(0);
				salaryCountTiming = Integer.parseInt(vp.getParamValue());
			}
			if(salaryCountTiming == 1){
				map.put("workerId", workerIds[i]);
				map.put("salaryCountFlag", 1);   //计算工资标志  添加已经计算过工资的数据
				List<Map<String,Object>> salaryInfos = salaryMapper.selectInfoToInsertSalaryForQuickInspection(map);
				if(!salaryInfos.isEmpty()){	
					worker worker = workerMapper.selectByPrimaryKey(workerIds[i]);
					List<Map<String,Object>> salaryInfoForInsert = this.getInsertInfoListByWorkerIdAndSalaryInfo(worker, salaryInfos);
					map.put("salaryInfoForInsert", salaryInfoForInsert);
					salaryMapper.insertSendBackTime(map);
				}
			}
		}
		return count;	
	}

	@Override
	public List<Map<String, Object>> getWorkGroupAndSumMarkTime(int dateType,
			String beginDate, String endDate, String realName,
			int salaryLine, int payOffType) {
		Map<String,Object> map = new HashMap<>();
		map.put("dateType", dateType);
		map.put("payOffType",payOffType);
		map.put("beginDate", beginDate);
		map.put("endDate", endDate);
		if(salaryLine >= 0){
			map.put("salaryLine", salaryLine*18);
		}else{
			map.put("salaryLine", null);
		}	
		if(realName.trim().length()>0){
			map.put("realName", realName);
		}else{
			map.put("realName", null);
		}
		return salaryMapper.selectWorkGroupAndSumMarkTime(map);
	}
	
	@Override
	public Map<String, Object> getTotleHoursAndTotleMoney(int dateType, String beginDate, String endDate, String realName,int salaryLine,int payOffType) {
		Map<String,Object> map = new HashMap<>();
		map.put("dateType", dateType);
		map.put("payOffType",payOffType);
		map.put("beginDate", beginDate);
		map.put("endDate", endDate);
		if(salaryLine >= 0){
			map.put("salaryLine", salaryLine*18);
		}else{
			map.put("salaryLine", null);
		}	
		if(realName.trim().length()>0){
			map.put("realName", realName);
		}else{
			map.put("realName", null);
		}
		return salaryMapper.selectTotleHoursAndTotleMoney(map);
	}
	
	
	/**
	 * 审核通用方法  将查询到的工资信息按照任务类型分别计算工资值
	 * @param workerId  工作者id
	 * @param salaryInfos  查询到的工资信息   最多两条    一条一层任务的信息  一条三层任务的信息  
	 * 		包含: workerId,  markTime,  timer, taskType 
	 * @return insertInfoList 将计算过的salaryValue添加到传入的map中返回   
	 * 		包含: workerId,  markTime,  timer, taskType, salaryValue  
	 */
	public List<Map<String,Object>> getInsertInfoListByWorkerIdAndSalaryInfo(worker worker,List<Map<String,Object>> salaryInfos){
		//处理一层三层工资添加到list中
		Map<String,Object> param = new HashMap<String, Object>();
		param.put("paramVlaue", worker.getWorkGroupCode());
		param.put("paramType", "workGroup");
		String salaryLayerOneAndLayerThree = paramMapper.selectRemarksByParamVlaueAndParamType(param); //查询参数表中的工资设置
		double salaryLayerOne = Double.parseDouble(salaryLayerOneAndLayerThree.split("/")[0]);  //一层任务工资
		double salaryLayerThree = Double.parseDouble(salaryLayerOneAndLayerThree.split("/")[1]);//三层任务工资
		List<Map<String,Object>> insertInfoList = new ArrayList<Map<String,Object>>();
		for (Map<String, Object> m : salaryInfos) {
			if(m.get("taskType").toString().equals("1")){
				m.put("salaryValue", (Double.parseDouble(m.get("markTime").toString())/3600)*salaryLayerOne);
			}else{
				m.put("salaryValue", (Double.parseDouble(m.get("markTime").toString())/3600)*salaryLayerThree);
			}
			insertInfoList.add(m);
		}
		return insertInfoList;
	}

	@Override
	public Map<String, Object> getSumMarkTimeAndSalaryValueForViewOfReferrals(int workerId, String date) {
		Map<String,Object> map = new HashMap<>();
		map.put("workerId", workerId);
		map.put("dateCondition", date);
		return salaryMapper.getSumMarkTimeAndSalaryValueForViewOfReferrals(map);
	}
	
	/**
	 * 一层三层任务计算工资,salary表插入数据,支付宝支付共同方法  
	 * @param workerId  工作者id
	 * @param salaryInfos   查询出的工资信息  List<Map<String, Object>> 包含workerId, markTime, timer, taskType 
	 * @param map 传入的查询条件 根据每个审核步骤的不同传入的内容不同
	 * @return  返回支付宝支付信息 AlipayInfo
	 */
	private AlipayInfo alipaySendAndSalaryInsert(int workerId, List<Map<String, Object>> salaryInfos, Map<String,Object> map ){
		//TODO  支付宝支付处理
		worker worker = workerMapper.selectByPrimaryKey(workerId);
		List<Map<String,Object>> salaryInfoForInsert = this.getInsertInfoListByWorkerIdAndSalaryInfo(worker, salaryInfos);
		map.put("salaryInfoForInsert", salaryInfoForInsert);
		// 调用支付宝转账  成功失败都要向alipayinfo中插入数据
		double salaryValue = 0.00;  //用于支付宝发送保留两位小数
		double markTime = 0.00;
		double salaryValue2 = 0.00; //用户数据库记录数据 不截取小数
		for (Map<String, Object> m : salaryInfoForInsert) { //将一层和三层任务的金额加到一起取两位小数 如果有的话
			salaryValue = salaryValue + Math.round(Double.parseDouble(m.get("salaryValue").toString())*100)/100.0;
			markTime = markTime + Double.parseDouble(m.get("markTime").toString());
			salaryValue2 = salaryValue2 + Double.parseDouble(m.get("salaryValue").toString());
		}
		String alipayOutBizNo = null;
		AlipayInfo newPayInfo = null;
		if(worker.getAlipayEnabled()&&salaryValue>0.1){ //工作者启用支付宝支付并且支付金额大于0.1元才进行支付宝支付
			alipayOutBizNo = UUID.randomUUID().toString().replaceAll("-", "").toUpperCase();
			AlipayInfo payInfo = new AlipayInfo();
			payInfo.setAlipayId(alipayOutBizNo);
			payInfo.setOutBizNo(alipayOutBizNo);
			payInfo.setPayeeAccount(worker.getWorkerPaypal()); 
			payInfo.setAmount(salaryValue);
			payInfo.setPayeeRealName(worker.getWorkerRealName());  
			payInfo.setWorkerId(worker.getWorkerId()); 
			try {
				newPayInfo = AlipayUtils.fundTransfer(payInfo);
				payInfoMapper.saveAlipayInfo(newPayInfo);
				if(newPayInfo.getIsSuccess()){
					map.put("alipayId", alipayOutBizNo);
				}else{
					map.put("alipayId", null);
				}
			} catch (AlipayApiException e) {
				System.out.println("###############################----支付宝支付报错----################################");
				e.printStackTrace();
			}
			salaryMapper.insertSalaryForOneAndThreeLayer(map);
			if(newPayInfo!=null&&newPayInfo.getIsSuccess()){
				salary ss = new salary();
				ss.setWorkerId(workerId);
				ss.setMarkTimeTotle(-markTime);
				ss.setTimer(new Date());
				ss.setPayOffTime(new Date());
				ss.setSalaryValue(-salaryValue2);
				ss.setAlipayId(alipayOutBizNo);
				insertSelective(ss);
			}
		}else{
			map.put("alipayId", null);
			salaryMapper.insertSalaryForOneAndThreeLayer(map);
		}
		return newPayInfo;
	}
	
	@Override
	public List<AlipayInfo> insertSalaryForModifyCompleted(List<Integer> recordIds) {
		Map<String,Object> map = new HashMap<String,Object>();
		//查询巡审审核的所有符合条件的的工作者id
		map.put("recordIds", recordIds);
		List<Integer> workerIds = salaryMapper.selectWorkerIdForInspByDay(map); //查询工作者id使用的巡审的方法  
		//向表中插入数据
		List<AlipayInfo> payList = new ArrayList<AlipayInfo>();
		if(!workerIds.isEmpty()){
			for (int i = 0; i < workerIds.size(); i++) {
				map.put("workerId", workerIds.get(i));
				map.put("salaryCountFlag", 0);   //计算工资标志  添加未计算过工资的数据
				List<Map<String,Object>> salaryInfos = salaryMapper.selectInfoToInsertSalaryForInspByDay(map);
				if(!salaryInfos.isEmpty()){
					AlipayInfo payInfo = this.alipaySendAndSalaryInsert(workerIds.get(i), salaryInfos, map);
					if(payInfo!=null){
						payList.add(payInfo);						
					}
				}
			}
		}
		return payList;
	}

	@Override
	public List<Map<String, Object>> getSalaryOfOneLayerAndThreelayerByWorkerId(int workerId, int dateType, String beginDate,
			String endDate, int payOffType) {
		Map<String,Object> map = new HashMap<>();
		map.put("workerId", workerId);
		map.put("dateType", dateType);
		map.put("payOffType",payOffType);
		map.put("beginDate", beginDate);
		map.put("endDate", endDate);	
		return salaryMapper.selectSalaryOfOneLayerAndThreelayerByWorkerId(map);
	}
}
